Client-side statement routing in distributed database

ABSTRACT

A system includes reception of a first query from a client device at a first database node of a database instance comprising two or more database nodes, determination of a second database node of the two or more database nodes associated with the first query, compilation of the first query at the first database node to generate first compiled code, and transmission of the first compiled code and a first identifier of the second database node from the first database node to the client device.

BACKGROUND

A distributed database system includes two or more database nodes. Eachnode executes one or more database processes and is associated withrespective data storage. To retrieve data from a distributed database, aclient application transmits a query to a database node which isdesignated to receive such queries. The designated database nodedetermines whether it should execute the query or route the query toanother database node for execution, and then executes or routes thequery based on the determination.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is a block diagram of a system according to some embodiments.

FIG. 2 is a flow diagram of a process according to some embodiments.

FIG. 3 is a flow diagram of a process according to some embodiments.

FIG. 4 is a block diagram illustrating operation of a system accordingto some embodiments.

FIG. 5 is a block diagram illustrating operation of a system accordingto some embodiments.

FIG. 6 is a block diagram illustrating operation of a system accordingto some embodiments.

FIG. 7 is a block diagram illustrating operation of a system accordingto some embodiments.

FIG. 8 is a block diagram illustrating operation of a system accordingto some embodiments.

FIG. 9 is a block diagram of a hardware system according to someembodiments.

DETAILED DESCRIPTION

The following description is provided to enable any person in the art tomake and use the described embodiments and sets forth the best modecontemplated for carrying out some embodiments. Various modifications,however, will remain readily apparent to those in the art.

FIG. 1 is a block diagram of system 100. System 100 represents a logicalarchitecture for describing some embodiments, and actual implementationsmay include more, fewer and/or different components arranged in anymanner. The elements of system 100 may represent software elements,hardware elements, or any combination thereof. For example, system 100may be implemented using any number of computing devices, and one ormore processors within system 100 may execute program code to causecorresponding computing devices to perform processes described herein.

Generally, each logical element described herein may be implemented byany number of devices coupled via any number of public and/or privatenetworks. Two or more of such devices may be located remote from oneanother and may communicate with one another via any known manner ofnetwork(s) and/or via a dedicated connection.

System 100 includes database instance 110, which is a distributeddatabase including database nodes 112, 114 and 116. Each of databasenodes 112, 114 and 116 includes at least one processor and a memorydevice. The memory devices of database nodes 112, 114 and 116 need notbe physically segregated as illustrated in FIG. 1, rather, FIG. 1 isintended to illustrate that each of database nodes 112, 114 and 116 isresponsible for managing a dedicated portion of physical memory,regardless of where that physical memory is located. The data storedwithin the memories of database nodes 112, 114 and 116, taken together,represent the full database of database instance 110.

In some embodiments, the memory of database nodes 112, 114 and 116 isimplemented in Random Access Memory (e.g., cache memory for storingrecently-used data) and one or more fixed disks (e.g., persistent memoryfor storing their respective portions of the full database).Alternatively, one or more of nodes 112, 114 and 116 may implement an“in-memory” database, in which volatile (e.g., non-disk-based) memory(e.g., Random Access Memory) is used both for cache memory and forstoring its entire respective portion of the full database. In someembodiments, the data of the full database may comprise one or more ofconventional tabular data, row-based data, column-based data, andobject-based data. Database instance 100 may also or alternativelysupport multi-tenancy by providing multiple logical database systemswhich are programmatically isolated from one another.

According to some embodiments, database nodes 112, 114 and 116 eachexecute a database server process to provide the data of the fulldatabase to database applications. More specifically, database instance110 may communicate with one or more database applications executed byclient 120 over one or more interfaces (e.g., a Structured QueryLanguage (SQL)-based interface) in order to provide data thereto. Client120 may comprise one or more processors and memory storing program codewhich is executable by the one or more processors to cause client 120 toperform the actions attributed thereto herein.

Client 120 may thereby comprise an application server executing databaseapplications to provide, for example, business reporting, inventorycontrol, online shopping, and/or any other suitable functions. Thedatabase applications may, in turn, support presentation applicationsexecuted by end-user devices (e.g., desktop computers, laptop computers,tablet computers, smartphones, etc.). Such a presentation applicationmay simply comprise a Web browser to access and display reportsgenerated by a database application.

The data of database instance 110 may be received from disparatehardware and software systems, some of which are not interoperationalwith one another. The systems may comprise a back-end data environmentemployed in a business or industrial context. The data may be pushed todatabase instance 110 and/or provided in response to queries receivedtherefrom.

Database instance 110 and each element thereof may also include otherunshown elements that may be used during operation thereof, such as anysuitable program code, scripts, or other functional data that isexecutable to interface with other elements, other applications, otherdata files, operating system files, and device drivers. These elementsare known to those in the art, and are therefore not described in detailherein.

FIG. 2 comprises a flow diagram of process 200 according to someembodiments. Process 200 may be executed by any database node of adistributed database instance according to some embodiments. Process 200and all other processes mentioned herein may be embodied incomputer-executable program code read from one or more non-transitorycomputer-readable media, such as a floppy disk, a CD-ROM, a DVD-ROM, aFlash drive, a fixed disk and a magnetic tape, and then stored in acompressed, uncompiled and/or encrypted format. In some embodiments,hard-wired circuitry may be used in place of, or in combination with,program code for implementation of processes according to someembodiments. Embodiments are therefore not limited to any specificcombination of hardware and software.

Initially, at S210, a query is received from a client. For example,database node 112 of instance 110 may receive a database query fromclient 120 at S210. The query may conform to any suitable compliablequery language that is or becomes known, such as, for example, SQL.

Next, the receiving database node compiles the query at S220. Accordingto some embodiments of S220, the database node executes a compilerassociated with the language of the query, and compilation of the queryresults in compiled code. The compiled code is executable by anydatabase node to execute the query on the data managed by the databasenode.

In this regard, a database node associated with the query is determinedat S230. The determined database node may be a database node that isdetermined to be suited to execute the query. For example, if the queryqueries Table T of the database instance, the determined database nodemay be a database node that manages and/or stores Table T.

The compiled query is transmitted to the client at S240. Alsotransmitted to the client at S240 is an identifier of the determineddatabase node. As will be described below with respect to process 300,the identifier may allow the client to route subsequent executions ofthe query to an appropriate database node (i.e., to the database nodeidentified by the identifier).

FIG. 3 comprises a flow diagram of process 300 according to someembodiments. Process 300 may be executed by a client device of adistributed database instance, such as but not limited to an applicationserver, according to some embodiments.

Flow initially cycles at S310 until an instruction to execute a query isreceived. The instruction may be generated by internal processes of anapplication executing on an application server and/or received from auser device at S310.

Once a query is received, it is determined at S320 whether the clientpossesses compiled code corresponding to the query, as discussed abovewith respect to process 200. In one example of S320, a client checks alocally-stored library (e.g., an SQLDBC client library) to determinewhether the compiled code resides in the library.

FIG. 4 illustrates system 400 according to some embodiments. Forpurposes of the present example, it is assumed that client 420 executesprocess 300, and that library 425 of client 420 contains no compiledquery code. Accordingly, the query to be executed is transmitted to afirst database node at S330.

In the FIG. 4 example, the query “Select . . . from T1” is transmittedto database node 412 at S330. Client 420 may transmit the query bycalling a “Prepare Query” API exposed by database node 412. According tosome embodiments, one or both of database nodes 414 and 416 also exposethe Prepare Query API and therefore the query could alternatively betransmitted to either of these nodes at S330.

As described with respect to S210 through S240 of process 200, databasenode 412 may proceed to compile the query, determine a database nodeassociated with the query (i.e., “N3”—referring to node 416 in whichassociated Table T1 is stored), and transmit the compiled code and anidentifier of the database node to the client. Returning to process 300,compiled code corresponding to the query and an identifier of a databasenode are received at S340. FIG. 4 illustrates transmission of the queryto database node 412 at S330 and reception of the compiled code andidentifier at S340.

The compiled code is stored in association with the identifier at S350.FIG. 5 illustrates storage of the compiled code 427 in association withthe identifier (i.e., “N3”) in library 425 according to someembodiments. In this regard, “in association” indicates that theidentifier may be located in memory by reference to the query Q1 and/orto the corresponding compiled code.

Next, at S360, an identifier associated with the compiled query isidentified. The identifier N3 is identified in the present example, andthe compiled query is transmitted to a database node associated with theidentifier at S370, as shown in FIG. 5. According to some embodiments,client 420 transmits the compiled query to the identified database nodeby calling an “Execute Query” API exposed by database node 416 andpassing the compiled code as a parameter thereof.

Database node 416, in response, executes the compiled code to performthe query and returns the query results to client 420. Client 420receives the query results at S380 and flow returns to S310 to awaitanother instruction.

FIG. 6 illustrates a scenario in which an instruction to execute anotherquery (e.g., Select . . . from T3 . . . ) is received at S310.Continuing with the present example, library 425 does not includecompiled code corresponding to the query so the query is transmitted toa database node at S330.

The query is transmitted to database node 414 in order to illustratethat process 200 may be independently executable by more than one nodeof a database instance. More specifically, database node 414 thencompiles the query, determines a database node associated with the query(i.e., “N2”—referring to node 414 in which associated Table T3 isstored), and transmits the compiled code and an identifier of thedatabase node to the client. Accordingly, the identifier may identifythe same database node used to compile the query.

The compiled code is stored in association with the identifier at S350,as shown in FIG. 7. Next, at S360, an identifier associated with thecompiled query is identified, and the compiled query is transmitted to adatabase node associated with the identifier at S370. In the FIG. 7case, the identified node is the same node from which the compiled codeand the identifier were received. The query results are received at S380and flow returns to S310 to await another instruction.

It will now be assumed that an instruction to execute query Q1 isreceived at S310. Referring to FIG. 8, the determination at S320 isaffirmative because library 425 includes compiled code corresponding toquery Q1. Accordingly, flow proceeds directly to S360 to identify anidentifier associated with the compiled code, and on to S370 to transmitthe compiled query to a database node associated with the identifier, asillustrated in FIG. 8. New query results are then received from thedatabase node at S380.

Therefore, according to some embodiments, second and subsequentexecutions of a query may avoid S330, S340 and S350 of process 300,since the client will already possess both the compiled query and anidentifier of a database node which is suitable for executing the query.

FIG. 9 is a block diagram of system 900 according to some embodiments.System 900 illustrates one hardware architecture implementing system 100and/or 400 as described above, but implementations of either system 100or 400 are not limited thereto. Elements of system 900 may thereforeoperate to execute process 200 and/or 300 as described above.

Database master 910 and each of database slaves 912, 914 and 916 maycomprise a multi-processor “blade” server. Each of database master 910and database slaves 912, 914 and 916 may operate as described hereinwith respect to database nodes, and database master 910 may performadditional transaction management functions and other master serverfunctions which are not performed by database slaves 912, 914 and 916 asis known in the art.

Database master 910 and database slaves 912, 914 and 916 are connectedvia network switch 920, and are thereby also connected to shared storage930. Shared storage 930 and all other memory mentioned herein maycomprise any appropriate non-transitory storage device, includingcombinations of magnetic storage devices (e.g., magnetic tape, hard diskdrives and flash memory), optical storage devices, Read Only Memory(ROM) devices, etc.

Shared storage 930 may comprise the persistent storage of a databaseinstance distributed among database master 910 and database slaves 912,914 and 916. As such, various portions of the data within shared storage930 may be allotted (i.e., managed by) one of database master 910 anddatabase slaves 912, 914 and 916.

Application server 940 may also comprise a multi-processor blade server.Application server 940, as described above, may execute databaseapplications to provide functionality to end users operating userdevices. Application server 940 may also execute process 300 to storecompiled query code and associated node identifiers in local memory (notshown) for use in routing and executing database queries.

Embodiments described herein are solely for the purpose of illustration.Those in the art will recognize other embodiments may be practiced withmodifications and alterations to that described above.

What is claimed is:
 1. A method implemented by a computing system inresponse to execution of program code by a processor of the computingsystem, the method comprising: receiving a first query from a clientdevice at a first database node of a database instance comprising two ormore database nodes; determining a second database node of the two ormore database nodes associated with the first query; compiling the firstquery at the first database node to generate first compiled code; andtransmitting the first compiled code and a first identifier of thesecond database node from the first database node to the client device;receiving a second query from the client device at the first databasenode; determining a third database node of the two or more databasenodes associated with the second query; compiling the second query togenerate second compiled code; transmitting the second compiled code anda second identifier of the third database node to the client device;storing the first compiled code in association with the first identifierin the client device; storing the second compiled code in associationwith the second identifier in the client device; determining, at theclient device, to execute the first query; identifying, at the clientdevice, the first compiled code and the first identifier based on thefirst query; transmitting the first compiled code from the client deviceto the second database node based on the first identifier; receiving thefirst compiled code at the second database node; generating queryresults using the first compiled code at the second database node;transmitting the query results to the client device; determining, at theclient device, to execute the second query; identifying, at the clientdevice, the second compiled code and the second identifier based on thesecond query; transmitting the second compiled code from the clientdevice to the third database node based on the second identifier;receiving the second compiled code at the third database node;generating second query results using the second compiled code at thethird database node; and transmitting the second query results to theclient device.
 2. A method according to claim 1, wherein determining thesecond database node comprises determining that the second database nodeis associated with a database table specified in the first query.
 3. Anon-transitory medium storing computer-executable program code, theprogram code executable by a computing device to: receive a first queryfrom a client device at a first database node of a database instancecomprising two or more database nodes; determine a second database nodeof the two or more database nodes associated with the first query;compile the first query at the first database node to generate firstcompiled code; transmit the first compiled code and a first identifierof the second database node from the first database node to the clientdevice receive a second query from the client device at the firstdatabase node; determine a third database node of the two or moredatabase nodes associated with the second query; compile the secondquery to generate second compiled code; transmit the second compiledcode and a second identifier of the third database node to the clientdevice; store the first compiled code in association with the firstidentifier in the client device; store the second compiled code inassociation with the second identifier in the client device; determine,at the client device, to execute the first query; identify, at theclient device, the first compiled code and the first identifier based onthe first query; transmit the first compiled code from the client deviceto the second database node based on the first identifier; receive thefirst compiled code at the second database node; generate query resultsusing the first compiled code at the second database node; transmit thequery results to the client device; determine, at the client device, toexecute the second query; identify, at the client device, the secondcompiled code and the second identifier based on the second query;transmit the second compiled code from the client device to the thirddatabase node based on the second identifier; receive the secondcompiled code at the third database node; generate second query resultsusing the second compiled code at the third database node; and transmitthe second query results to the client device.
 4. A medium according toclaim 3, wherein the program code executable by the computing device todetermine the second database node comprises program code executable bya computing device to determine that the second database node isassociated with a database table specified in the first query.
 5. Asystem comprising: a client device comprising a processor and a memory;a first database node comprising a first processor and a first memory; asecond database node comprising a second processor and a second memory,the second database node to: receive a first query from the clientdevice, determine the first database node as being associated with thefirst query; compile the first query to generate first compiled code;transmit the first compiled code and a first identifier of the firstdatabase node to the client device; the second database node further to:receive a second query from the client device; determine that the seconddatabase node is associated with the second query; compile the secondquery to generate second compiled code; and transmit the second compiledcode and a second identifier of the second database node to the clientdevice; the client device to: store the first compiled code inassociation with the first identifier in the memory; store the secondcompiled code in association with the second identifier in the memory;determine to execute the first query; identify the first compiled codeand the first identifier in the memory based on the first query;transmit the first compiled code to the first database node based on thefirst identifier; determine to execute the second query; identify thesecond compiled code and the second identifier in the memory based onthe second query; and transmit the second compiled code to the seconddatabase node based on the first identifier; the first database node to:receive the first compiled code; generate query results using the firstcompiled code; transmit the query results to the client device;determine, at the client device, to execute the second query; identify,at the client device, the second compiled code and the second identifierbased on the second query; and transmit the second compiled code fromthe client device to the third database node based on the secondidentifier; and the second database node further to: receive the secondcompiled code; generate second query results using the second compiled;and transmit the second query results to the client device.